﻿using System;
using System.Collections.Generic;
using System.Globalization;
using Lucene.Net.Documents;

namespace TShooter.TfsSearch.EngineModel
{
    public class IndexDocument
    {
        private int _ID;
        private int _Revision;
        private string _Title;
        private readonly Dictionary<string,Field> _Properties = new Dictionary<string, Field>();

        public IndexDocument()
        {
        }

        public IndexDocument(int _ID, int _Revision, string _Title)
        {
            this._ID = _ID;
            this._Revision = _Revision;
            this._Title = _Title;
        }

        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        public int Revision
        {
            get { return _Revision; }
            set { _Revision = value; }
        }

        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

        public void AddProperty(string name, string value)
        {
            _Properties.Add(name, new Field(name, value, Field.Store.YES, Field.Index.UN_TOKENIZED));
        }

        public void AddProperty(string name, int value)
        {
            AddProperty(name, value.ToString());
        }

        public void AddProperty(string name, DateTime value)
        {
            AddProperty(name, value, DateTools.Resolution.DAY);
        }

        public void AddProperty(string name, DateTime value, DateTools.Resolution resolution)
        {
            AddProperty(name, DateTools.DateToString(value, resolution));
        }

        public void AddProperty(string name, bool value)
        {
            AddProperty(name, value.ToString(CultureInfo.InvariantCulture));
        }

        public void AddSearchOnlyProperty(string name, string value)
        {
            _Properties.Add(name, new Field(name, value, Field.Store.NO, Field.Index.UN_TOKENIZED));
        }

        public void AddSearchOnlyProperty(string name, int value)
        {
            AddSearchOnlyProperty(name, value.ToString());
        }

        public void AddSearchOnlyProperty(string name, DateTime value)
        {
            AddSearchOnlyProperty(name, value, DateTools.Resolution.DAY);
        }

        public void AddSearchOnlyProperty(string name, DateTime value, DateTools.Resolution resolution)
        {
            AddSearchOnlyProperty(name, DateTools.DateToString(value, resolution));
        }

        public void AddSearchOnlyProperty(string name, bool value)
        {
            AddSearchOnlyProperty(name, value.ToString(CultureInfo.InvariantCulture));
        }

        public void AddText(string name, string value)
        {
            _Properties.Add(name, new Field(name, value, Field.Store.NO, Field.Index.TOKENIZED));
        }

        public Document ToDocument()
        {
            return null;
        }
    }
}
